<script>
	export default {
		onLaunch: function() {
			var _this=this;
			console.log('App Launch');
			
			// 设置版本号
			_this.globalData.versionNo = '1.0.6';
			_this.globalData.versionNoIos = '1.0.6';
			
			var token = uni.getStorageSync('token');
			
			var os='';
			uni.getSystemInfo({
				success: function (res) {
					os=res.platform
				}
			});
			
				
			// 原始id
			this.globalData.originalId = 'gh_80176abcce55';
			// #ifdef MP-WEIXIN
				_this.defaultLogin();
				
				var address=uni.getStorageSync('address');
				_this.getMapKey();
				
				os=os+'_weixin';
			// #endif
			// #ifdef APP-PLUS
				os=os+'_app';
				if(token){
					_this.$isResolve();
				}else{
					console.log('wx=============================1')
					uni.redirectTo({
						url:'/pages/login/loginWx'
					})
				}
				// _this.getAddress();
			// #endif
			uni.setStorageSync('os', os);
		},
		methods: {
			// 小程序端默认登录
			defaultLogin() {
				var _this = this;
				uni.login({
					success: function(loginRes) {
						console.log(loginRes);
						_this.$u.post('/api/Login/wxLogin', {
							code: loginRes.code
						}).then(res => {
							console.log('==小程序默认登录==');
							console.log(res);
							if(res.data.is_vip=='--' || res.data.isNotice==1){
								uni.setStorageSync('token', '');
								uni.setStorageSync('userInfo','');
								_this.$isResolve();
								return
							}
							// 缓存token
							uni.setStorageSync('token', res.data.token);

							// 缓存用户信息
							uni.setStorageSync('userInfo', res.data);

							_this.$isResolve();
							// _this.getDefaultWorksite();
						}).catch(err => {
							console.log(err);
						})
					}
				});
			},

			// 获取默认工地
			getDefaultWorksite() {
				var _this = this;
				_this.$u.get('/api/project.index/getDefault', {}).then(res => {
					console.log('==获取默认工地==');
					console.log(res);
					// 缓存默认工地信息
					uni.setStorageSync('defaultWorksite', JSON.stringify(defaultWorksite));
				})
			},
			
			
			getAddress() {
				
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					isHighAccuracy: true,
					success: (res) => {
						var address = res.address.city + res.address.district + res.address.street ;
						uni.setStorageSync('address', address);
						uni.setStorageSync('longitude', res.longitude);
						uni.setStorageSync('latitude', res.latitude);
					}
				});
			},

			// 获取数据辞典信息
			getMapKey() {
				let _this = this;
				_this.$u.get('/api/plus.dictionaries/getDetail', {
					name: 'mapkey',
				}).then(res => {
					console.log("==获取数据辞典信息==");
					console.log(res);
					var mapKey = res.data.value;
					_this.getLocation(mapKey);

					// 缓存地图key
					uni.setStorageSync('mapKey', mapKey);
				}).catch(res => {
					console.log(res);
				})
			},
			
			
			
			// 获取当前位置
			getLocation(mapKey) {
				// console.log(mapKey);
				let _this = this;
				wx.getLocation({
					type: 'wgs84',
					// geocode: true,
					success: function(res) {
						console.log('==获取当前位置的经纬度-成功==');
						console.log(res);

						_this.longitude = res.longitude;
						_this.latitude = res.latitude;

						// 设置经纬度缓存
						uni.setStorageSync('longitude', res.longitude);
						uni.setStorageSync('latitude', res.latitude);

						// 引入腾讯地图SDK核心类
						var QQMapWX = require('@/util/qqmap-wx-jssdk.min.js');
						var qqmapsdk = new QQMapWX({
							key: mapKey,
						});

						// 根据经纬度获取所在位置
						qqmapsdk.reverseGeocoder({
							location: {
								longitude: res.longitude,
								latitude: res.latitude,
							},
							success: function(res) {
								console.log("==根据经纬度获取所在位置==");
								console.log( res.result.formatted_addresses.rough);

								// 设置城市缓存
								uni.setStorageSync('province', res.result.ad_info.province);
								uni.setStorageSync('city', res.result.ad_info.city);
								uni.setStorageSync('area', res.result.ad_info.district);
								uni.setStorageSync('address', res.result.formatted_addresses.rough);
							}
						});
					},
					fail: function(res) {
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	/*引入uview的css */
	@import "uview-ui/index.scss";

	/* 页面背景色 */
	page {
		font-family: 'PingFang SC',
			"Helvetica Neue",
			Helvetica,
			"microsoft yahei",
			arial,
			STHeiTi,
			sans-serif;
		font-size: 28rpx;
		color: #262626;
		background-color: #F5F5F5;
	}

	// 重置button
	button {
		padding: 0;
		margin: 0;
		background: transparent;
		height: 100%;
		line-height: inherit;
		font-size: inherit;
	}

	button::after {
		border: 0;
		background-color: none;
	}

	/* 隐藏滚动条 */
	scroll-view ::-webkit-scrollbar {
		display: none;
	}

	/* placeholder字体颜色 */
	.placeholderColor {
		color: #B3B3B3;
	}

	/* 暂无数据 */
	.dataEmpty_con {
		width: 100%;
		padding: 30rpx 0;
		text-align: center;
		overflow: hidden;
	}

	/**
	 * 表单 start
	 */
	.formCon {}

	.formItem {
		padding: 30rpx 20rpx;
		font-size: 28rpx;
		background-color: #F5F6F8;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.formItem:last-child {
		border-bottom: 0;
	}

	.formItem .label {
		width: 100%;
		color: #333;
		padding-bottom: 20rpx;
	}

	.formItem .label text {
		font-size: 24rpx;
		color: #FF0000;
		margin-right: 10rpx;
	}

	.formItem .controls {
		width: 100%;
	}

	.formItem .input {
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 28rpx;
		box-sizing: border-box;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.formItem .textarea {
		width: 100%;
		height: 250rpx;
		line-height: 30rpx;
		padding: 20rpx;
		text-align: left;
		font-size: 28rpx;
		box-sizing: border-box;
		background: #f8f8f8;
		border-radius: 30rpx;
		overflow: hidden;
	}

	.formItem.formFlex {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.formItem.formFlex .label {
		flex: 1;
		padding: 0;
		width: auto;
	}

	.formItem.formFlex .controls {
		flex: 3;
		text-align: right;
		width: auto;
	}

	.formItem.formFlex .input {
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		text-align: right;
	}

	.formItem.formFlex .pickerCon {
		width: 100%;
	}
	
	

	.formPost_con {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-content: center;
	}

	.formPost_con .submitBtn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		color: $uni-color-white;
		background: $uni-color-active;
		border-radius: 20rpx;
		overflow: hidden;
	}

	/* 上传图片 */
	.uploadList {
		clear: both;
		/* overflow: hidden; */
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}

	.uploadList .uploadItem {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
		background-color: #efefef;
		box-sizing: border-box;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		position: relative;
	}

	.uploadList .uploadItem image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}

	.uploadList .uploadItem:nth-child(5n),
	.uploadList .uploadBtn {
		margin-right: 0;
	}

	.uploadList .uploadBtn {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.uploadList .uploadItem .delPic {
		position: absolute;
		right: 0rpx;
		top: 0rpx;
		z-index: 100;
	}

	/**
	 * 表单 end
	 */

	// 选项卡
	.recordTab_box {
		background: #f0f6ff;
		overflow: hidden;
	}

	.recordTab_con {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.recordTabItem {
		width: 375rpx;
		border-bottom: 90rpx solid transparent;
		box-sizing: border-box;
		position: relative;
	}

	.recordTabItem text {
		font-size: 32rpx;
		font-weight: bold;
		text-align: center;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, 50%);
	}

	.recordTabItem:nth-child(1).active {
		width: 375rpx;
		color: $uni-color;
		border-bottom: 90rpx solid #fff;
		border-right: 15rpx solid transparent;
		border-top-right-radius: 30rpx;
	}

	.recordTabItem:nth-child(2).active {
		width: 375rpx;
		color: $uni-color;
		border-bottom: 90rpx solid #fff;
		border-left: 15rpx solid transparent;
		border-top-left-radius: 30rpx;
	}

	/**
	 * 记工记账表单
	 */
	.handleList_box {
		padding: 15rpx 30rpx;
		background-color: $uni-color-white;
	}

	.handleList_con {
		padding: 15rpx 0;
		font-size: 28rpx;
		overflow: hidden;
		display: flex;
		align-items: center;
	}
	
	.handleList_con .pickerCon input{
		width: 100%;
	}

	.handleLabel {
		width: 90rpx;
		color: $uni-color;
	}

	.handleLabelMedium {
		width: 120rpx;
	}

	.handleLabelLong {
		width: 150rpx;
	}

	.handleList {
		flex: 2;
		display: flex;
		align-items: center;
	}

	.handleItem {
		flex: 1;
		padding: 0 20rpx;
		height: 90rpx;
		color: $uni-color;
		background: #f0f0f0;
		border-radius: 10rpx;
		overflow: hidden;
		margin-right: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.handleItem:last-child {
		margin-right: 0;
	}

	.handleItem.handleActive {
		color: $uni-color-white;
		background-color: $uni-color-active;
	}

	.handleItem input {
		height: 90rpx;
		line-height: 90rpx;
	}

	.handleItem.handleActive input {
		color: $uni-color-white;
	}

	.handleItem.handleActive .overInput {
		color: $uni-color-white;
	}

	.handleItem .overLine {
		width: 1rpx;
		height: 26rpx;
		background-color: #B3B3B3;
		margin: 0 20rpx;
	}

	.handleItem.handleActive .overLine {
		background-color: #fff;
	}

	.handleItem .overIcon {
		width: 26rpx;
		height: 26rpx;
	}

	.handleList_con .baoCon {
		width: 100%;
		border-bottom: 2rpx solid #eee;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.handleList_con .baoCon input {
		flex: 2;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 52rpx;
		margin-right: 20rpx;
	}

	.handleList_con .baoCon text {
		font-size: 28rpx;
		color: $uni-color;
	}

	.handleList_con .textareaCon {
		width: 100%;
	}

	.handleList_con .textareaCon textarea {
		width: 100%;
		height: 100rpx;
		line-height: 30rpx;
		padding: 20rpx;
		font-size: 28rpx;
		background: #f0f0f0;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	.handleList_con .photoCon {
		display: flex;
		align-items: center;
	}
	
	.handleList_con .photoCon image {
		width: 80rpx;
		height: 80rpx;
		border-radius: 10rpx;
		overflow: hidden;
		margin-right: 20rpx;
	}
	
	.handleList_con .photoCon text {
		color: $uni-color-active;
	}
	
	.handleList_con .pickerCon {
		flex: 2;
		padding: 20rpx 30rpx;
		background: #f0f0f0;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.handleList_con .inputCon {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.handleList_con .inputCon input {
		flex: 1;
		height: 90rpx;
		line-height: 90rpx;
		padding: 0 30rpx;
		background: #f0f0f0;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		margin-right: 20rpx;
	}

	.handleList_con .inputCon input:last-child {
		margin-right: 0;
	}

	// 底部按钮
	.handlePost_con {
		width: 100%;
		padding: 30rpx;
		font-size: 28rpx;
		font-weight: bold;
		border-top: 1rpx solid #eee;
		background-color: $uni-color-white;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.handleFixed {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 9999;
	}

	.handlePost_con .delBtn {
		width: 240rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #ff4241;
		border: 2rpx solid #ff4241;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		margin-right: 20rpx;
	}

	.handlePost_con .cancelBtn {
		width: 240rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: $uni-color-active;
		border: 2rpx solid $uni-color-active;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		margin-right: 20rpx;
	}

	.handlePost_con .completeBtn {
		flex: 2;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: $uni-color-white;
		background-color: $uni-color-active;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.handleList_con .payCon {
	  width: 100%;
	  display: flex;
	  justify-content: space-between;
	  align-items: center;
	 }
	 
	 .handleList_con .payCon input {
	  width: 100%;
	  height: 90rpx;
	  line-height: 90rpx;
	  padding: 0 30rpx;
	  background: #f0f0f0;
	  border-radius: 10rpx;
	  box-sizing: border-box;
	  overflow: hidden;
	 }
	 
	 
	 .uni-picker-container .uni-picker-header{                //picker头部背景色
	 
		background-color: #327FE8;
	 
	 }
</style>
